package me.szlx.thing;

import java.io.Serializable;

public interface Thing extends Serializable {
    /**
     * 标识
     * @return 标识
     */
    Object getId();

    /**
     * 名称
     * @return 名称
     */
    String getName();

    /**
     * 描述
     * @return 描述
     */
    String getDescription();

    /**
     * 特性
     * @return 特性
     */
    Traits getTraits();

    default boolean match(TraitLet... traits) {
        if (traits == null && traits.length == 0) {
            return true;
        }
        if (getTraits() == null) {
            return false;
        }
        return getTraits().match(Traits.of(traits));
    }

    default boolean like(Thing thing, TraitLet... traits) {
        if (thing == null) {
            return false;
        }
        Traits theTraits = traits != null && traits.length != 0 ? Traits.of(traits) : thing.getTraits();
        return match(theTraits) == thing.match(theTraits);
    }

    static Thing create(Object code, String name) {
        ThingVO vo = new ThingVO();
        vo.setId(code);
        vo.setName(name);
        return vo;
    }

    static Thing create(Object code, String name, String description) {
        ThingVO vo = new ThingVO();
        vo.setId(code);
        vo.setName(name);
        vo.setDescription(description);
        return vo;
    }

    static Thing create(Object code, String name, Traits traits) {
        ThingVO vo = new ThingVO();
        vo.setId(code);
        vo.setName(name);
        vo.setTraits(traits);
        return vo;
    }

    static Thing create(Object code, String name, String description, Traits traits) {
        ThingVO vo = new ThingVO();
        vo.setId(code);
        vo.setName(name);
        vo.setDescription(description);
        vo.setTraits(traits);
        return vo;
    }
}

